
/* $Log: Application.c,v $
/* Revision 1.17  2009/11/30 15:33:34  dimitrip
/* Added new command - SM ( Send SMS message )
/*
/* Revision 1.16  2009/11/11 09:20:39  dimitrip
/* Car Petrol Blocking update: if (registration > 2 min) reset;
/*
/* Revision 1.15  2009/11/03 10:54:19  dimitrip
/* Add "Car. Petrol Blocking" application
/*
/* Revision 1.14  2009/10/29 10:25:12  dimitrip
/* Add Print_SMS application
/*
/* Revision 1.13  2007/11/04 17:51:32  dimitrip
/* *** empty log message ***
/*
/* Revision 1.12  2007/11/01 17:10:46  dimitrip
/* *** empty log message ***
/*
/* Revision 1.11  2007/10/05 18:31:50  Administrator
/* Implemented RF transmitter;
/* see RFT & RT command;
/*
/* Revision 1.10  2007/09/09 10:56:59  dimitrip
/* Add RF Remote, ARM mode;
/*
/* Revision 1.9  2007/08/26 16:06:23  dimitrip
/* RF - OK;
/*
/* Revision 1.8  2007/02/05 12:30:37  dimitrip
/* *** empty log message ***
/*
/* Revision 1.8  2007/01/08 16:26:40  dimitrip
/* *** empty log message ***
/*
/* Revision 1.7  2006/12/21 16:13:25  dimitrip
/* *** empty log message ***
/*
/* Revision 1.6  2006/12/17 17:00:07  dimitrip
/* *** empty log message ***
/*
/* Revision 1.5  2006/12/16 21:38:37  Dima
/* *** empty log message ***
/*
/* Revision 1.4  2006/12/14 15:58:21  dimitrip
/* *** empty log message ***
/* */

#include "main.h"
#include "Car_PetrolBlocking.h"
const char Revision_Basic[] = "$Revision: 2 $";

near bit System_Mode;

unsigned char PhoneNumber[CALL_NUMBER_SIZE];
unsigned char NMS_PhoneNumber[CALL_NUMBER_SIZE];
unsigned char SysState, NextState, PrevState;

void (*Func) (void);
void (*Execute_Module_1) (void);

near REGISTRATION_STATUS RegistrationStatus = 0;

void MainStateMachine_Init( void )
{
	SysState = REGISTRATION;
	SMS_Monitor_Cycle = 18;
	System_Mode = DISARM;
}


void MainStateMachine ( void )
{

#ifndef   WITHOUT_SIM
	if ( Time_1000ms && --SMS_Monitor_Cycle == 0 )
	{
		if ( Execute_Module_1 == NULL )
			Execute_Module_1 = SMS_Monitor;
		else
			SMS_Monitor_Cycle = 6;
	}
#endif

	if ( ModemStatus == MODEM_NOT_ANSWER )
	{
		SysState = SAVE_MODE;
	}

	switch ( SysState )
	{
		case SAVE_MODE:
			LED = 0;
			PIN_MODEM_POWER = FALSE;
			PIN_MODEM_POWER = FALSE;
			delay_ms(4000);
			RESET();
			break;

		case STOP_MACHINE:
			
			break;

		case REGISTRATION:
			if ( Registration() == TRUE )
			{
				SysState = IDLE;
				putsf("\r\nRegistration - OK\r\n", AUX_PORT);
			}
			break;	

		case IDLE:
#if defined(APP_DEBUG)						
			if( Time_1Min )
				Debug("\nIDLE");
#endif
			break;

		case STATE_ARM:
			if( Time_1Min )
				putsf("\nARM", AUX_PORT);
			break;	

		case RF_LEARN_MODE:
			RF_LearMode();
			break;	

	
		default :
			;
	}
} 

/* 
			
			if ( !InputsState.INP_1 )
				OUT_0 = OUT_BLINK;
			else
				OUT_0 = HIGH;


			if ( !InputsState.INP_2 )
				OUT_1 = OUT_BLINK;
			else
				OUT_1 = HIGH;


			if ( !InputsState.INP_3 )
				OUT_2 = OUT_BLINK;
			else
				OUT_2 = HIGH;


			if ( !InputsState.INP_4 )
				OUT_3 = OUT_BLINK;
			else
				OUT_3 = HIGH;

 */
